<template>
	<view>
		<view class="Lu-busin-box" v-if="userInfo.identity_type == 1">
			<view class="Lu-busin-img">
				<image class="Lu-busin-img2" src="https://www.quyidian.com.cn/uploads/tool/join.png" mode="widthFix"></image>
			</view>
			<view class="Lu-busin-btn" @click="buyshiye">
				支付360元，成为事业合伙人
			</view>
		</view>
		
		<view class="Lu-share-box" v-else>
			<view>
				<image :src='headerImg' mode="widthFix"></image>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	import md5 from 'js-md5';
	export default {
		computed: {
			...mapState(['hasLogin','userInfo','openId','apiUrl'])
		},
		data() {
			return {
				userid:'',
				shiyemoney:360.00,
				headerImg:''
			}
		},
		onLoad:function(options){
			this.geterma()
			
		},
		onShow:function(){
			
		},
		methods:{
			buyshiye:function(){
				const shortName = this.openId.substring(0,this.userInfo.id%10) + this.shiyemoney*100;
				uni.request({
					url:this.apiUrl+ 'api/payment',
					data:{
						money:this.shiyemoney*100,
						sign:md5(shortName),
						type:2
					},
					method:'POST',
					header:{
						openid:this.openId
					},
					success: (res) => {
						console.log(res.data.data)
						const _this = this
						uni.requestPayment({
						    provider: 'wxpay',
						    timeStamp: res.data.data.timeStamp,
						    nonceStr: res.data.data.nonceStr,
						    package: res.data.data.package,
						    signType: res.data.data.signType,
						    paySign: res.data.data.paySign,
						    success: function (res) {
						       uni.showModal({
						           title: '支付成功',
								   content:'支付成功',
						           success: function (res) {
						           
						           }
						       }),
							   uni.request({
									url:_this.apiUrl+'api/userInfo',
									method:"POST",
									header:{
										openid:_this.openId
									},
									success: (res) => {
										_this.$store.commit('login', res.data.data);
									}
							   })
						    },
						    fail: function (err) {
						        uni.showModal({
						            title: '支付失败',
									  content:'支付失败',
						            success: function (res) {
						                if (res.confirm) {
						                   
						                } else if (res.cancel) {
						                    
						                }
						            }
						        })
						    }
						});
					}
				})
			},
			geterma:function(){
				uni.request({
					url:this.apiUrl+'api/get_erma',
					data:{},
					method:'POST',
					header:{
						openid:this.openId
					},
					success: (res) => {
						this.headerImg = res.data.data.headImg
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #f5f5f5;
	}
	.Lu-busin-box{
		position: relative;
	}
	.Lu-busin-img{
		.Lu-busin-img2{
			width: 750rpx;
		}
	}
	.Lu-busin-btn{
		background-image: url(~@/static/image/business/btnbg.png);
		background-size: 710rpx 100rpx;
		background-repeat: no-repeat;
		width: 710rpx;
		height: 100rpx;
		
		text-align: center;
		line-height: 100rpx;
		font-size: 36rpx;
		color: #fff;
		position: absolute;
		bottom: 10rpx;
		left: 20rpx;
	}
	.Lu-share-box{
		image{
			width: 100%;
		}
	}
</style>
